<template>
	<section style="width:100%">
		<section>
			<el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
				<el-form :inline="true">
					<el-form-item>
						<el-input v-model="userId" placeholder="玩家ID"></el-input>
					</el-form-item>
					<el-form-item>
						<el-button type="primary" v-on:click="getUsers(pageSize)">查询</el-button>
					</el-form-item>
					<el-form-item label="刷新" style="margin-left: 50px">
						<el-radio-group v-model="autoBreak" @change="changeBreak">
							<el-radio :label="5000">5秒</el-radio>
							<el-radio :label="15000">15秒</el-radio>
							<el-radio :label="300000">30秒</el-radio>
							<el-radio :label="0">停止</el-radio>
						</el-radio-group>
					</el-form-item>

				</el-form>
			</el-col>
			<!--列表-->
			<el-table :data="users" stripe highlight-current-row v-loading="listLoading"  style="width: 100%;" :default-sort = "{prop: 'applytime', order: 'descending'}">
				<el-table-column prop="id" label="单号">
				</el-table-column>
				<el-table-column prop="userid" label="玩家ID"  width="100" sortable>
				</el-table-column>
				<el-table-column prop="nickname" label="玩家昵称" width="120">
				</el-table-column>
				<el-table-column prop="amount" label="提现金额" width="120" sortable>
				</el-table-column>
				<el-table-column prop="applytime" label="申请时间" width="200" sortable>
				</el-table-column>
				<el-table-column prop="setTime" label="处理时间" width="200">
				</el-table-column>
				<el-table-column prop="operatorid" label="处理人ID" width="120">
				</el-table-column>
				<el-table-column prop="bankType" label="提现方式" width="100">
				</el-table-column>
				<el-table-column prop="accountid" label="到账账号" min-width="120">
					<template slot-scope="scope">
						<span v-if="scope.row.accounttype == 2">{{scope.row.account}}</span>
						<span v-else>{{scope.row.cardNumber}}</span>
					</template>
				</el-table-column>
				<el-table-column prop="depositName" label="到账姓名" width="120">
				</el-table-column>
				<el-table-column prop="stateTxt" label="处理状态" width="100" >
				</el-table-column>
				<!--<el-table-column prop="cardName" label="到账账号" width="100" >-->
				<!--</el-table-column>-->
				<el-table-column prop="bankName" label="到账银行" width="100" >
				</el-table-column>
				<el-table-column prop="bankProvince" label="到账银行开户行" width="150">
				</el-table-column>
				<el-table-column label="操作" min-width="200" fixed="right">
					<template slot-scope="scope" v-if="scope.row.state == 0">
						<!--<el-button type="primary" size="small" >处理完成</el-button>-->
						<el-button type="primary" size="small" @click="editCash(scope.row.id,'1')">成功</el-button>
						<el-button type="primary" size="small" @click="editCash(scope.row.id,'2')">拒绝</el-button>
					</template>
				</el-table-column>
			</el-table>
			<!--工具条-->
			<el-col :span="24" class="toolbar">
				<el-pagination layout="sizes, total, prev, pager, next" :page-sizes="[15, 30, 50]" @current-change="handleCurrentChange" @size-change="handleSizeChange"  :page-size="pageSize" :total="total" style="float:right;">
				</el-pagination>
			</el-col>
		</section>
	</section>
</template>

<script>
	import base64 from '../../api/base64'
	export default {
		data() {
			return {
                userId:'',
                listLoading:false,
                users:[],
                total:0,
                autoBreak:5000,
                page:1,
				pageSize:15
			}
		},
		methods: {
            changeBreak(val){
                window.clearInterval(window.timer)
                if(val != 0){
                    window.timer = window.setInterval(()=>{
                        this.getUsers(this.pageSize);
                    },val)
				}
			},
            handleSizeChange(val) {
                this.pageSize = val
                this.getUsers(this.pageSize);
            },
			handleCurrentChange(val) {
				this.page = val;
				this.getUsers(this.pageSize);
			},
			//获取用户列表
			getUsers(page) {
                this.listLoading = true;
                this.$axios.get('/user-withdrawls?userid='+this.userId+'&index='+this.page+'&size='+page,{},this.global().token).then((res)=>{
                    if (res.status == 200){
                        this.total = res.data.count
                        let userTable = res.data.data
                        let base = new base64.Base64()
                        userTable.forEach((val)=>{
                            if (val.nickname){
                                val.nickname =  base.decode(val.nickname)
							}
							if (val.amount){
                                val.amount = parseFloat(val.amount)/1000
							}
                            val.applytime = this.changeDate(val.submitat)
							if (!(val.transferat || val.transferat == '0')){
                                val.setTime = this.changeDate(val.transferat)
							}else{
                                val.setTime = ''
							}
							if(val.operatorid == '0'){
                                val.operatorid = ''
							}
							if (val.accounttype){
                                val.bankType = val.accounttype.toString().replace('1','银行卡').replace('2','支付宝')
							}
							if (val.accounttype == 1){
                                val.depositName = val.cardName
                            }else{
                                val.depositName = val.allipayName
                            }
                            val.stateTxt = val.state.toString().replace('0','未处理').replace('1','处理完成').replace('2','已拒绝')
                        })
                        this.users = userTable
                        this.listLoading = false
                    }else{
                        this.$message({message: res.data, type: 'error'});
                        this.listLoading = false
                    }
                })
			},
            editCash(id,state){
                this.$confirm('确认修改吗?', '提示', {
                    //type: 'warning'
                }).then(() => {
                    this.$axios.patch('/user-withdrawl/'+id,{state:parseInt(state)},this.global().token).then((res)=>{
                        if (res.status == 200){
                            this.$message({message: '操作成功', type: 'success'});
                            this.getUsers(this.pageSize)
                        }else{
                            this.$message({message: res.data, type: 'error'});
                        }
                    })
                }).catch(() => {

                });

			}
		},
		created() {
            this.getUsers(this.pageSize);
            window.timer = window.setInterval(()=>{
                this.getUsers(this.pageSize);
            },this.autoBreak)
		}
	}

</script>

<style scoped lang="stylus">
	.agent-path
		display flex
		padding-bottom 10px
		&>p
			padding-right 10px
		&>h3
			cursor pointer
</style>